package keeto.com.vn.classified.task;

import java.io.IOException;

import keeto.com.vn.classified.core.ClassifiedCore;
import keeto.com.vn.classified.core.ClassifiedListener;
import keeto.com.vn.classified.network.IProtocol;
import keeto.com.vn.classified.request.GetProductCateFourRequest;
import keeto.com.vn.classified.response.GetProductCateFourResponse;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
public class TaskGetProductSubCate extends AbstractTask{
	String hightLight;
	String GuaranteeStoreId;
	int CategoryId;
	int pageLimit;
	
	String categoryType;
	String itemID;
	int pageNumber;
	int SortBy;
	
	
	
	public TaskGetProductSubCate(ClassifiedListener listener, ClassifiedCore core,
			String hightLight, String guaranteeStoreId, int categoryId,
			 int pageLimit, String categoryType, String itemID, int pageNumber, int SortBy) {
		super(listener, core);
		this.hightLight = hightLight;
		this.GuaranteeStoreId = guaranteeStoreId;
		this.CategoryId = categoryId;
		this.pageLimit = pageLimit;
		this.categoryType = categoryType;
		this.itemID = itemID;
		this.pageNumber = pageNumber;
		this.SortBy = SortBy;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException, IOException {
		GetProductCateFourRequest request = new GetProductCateFourRequest();
		request.setCategoryId(CategoryId);
		request.setGuaranteeStoreId(GuaranteeStoreId);
		request.setHighlight(hightLight);
		request.setPageLimit(pageLimit);
		request.setCategoryType(categoryType);
		request.setItemId(itemID);
		request.setPageNumber(pageNumber);
		request.setCategoryType(categoryType);
		request.setSortBy(SortBy);
		GetProductCateFourResponse response = json.getProductSubCate(request);
		
		for (ClassifiedListener listener : listeners){
			listener.finishGetProductCateFour(response.getReturnCode(), response.getList_productcatefour(), response.getCount());
		}
	}

	@Override
	public void timeoutCallback() {
		for (ClassifiedListener ilistener:core.copyAndReconstructListeners(listener)){
			ilistener.finishGetProductCateFour(IProtocol.STATUS_CODE_CONNECTION_TIMEOUT_502, null, 0);
		}
	}

}
